package io.renren.modules.coin.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import io.renren.common.dto.RobotRequestDto;
import io.renren.common.enums.YesOrNoEnum;
import io.renren.modules.app.annotation.LoginUser;
import io.renren.modules.app.entity.UserEntity;
import io.renren.modules.coin.entity.RobotLogEntity;
import io.renren.modules.coin.service.RobotLogService;
import io.renren.modules.sys.controller.AbstractController;
import io.renren.modules.sys.entity.SysUserEntity;
import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 机器人日志表
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2021-08-22 18:07:08
 */
@Api("机器人相关接口")
@RestController
@RequestMapping("robot/robotlog")
public class RobotLogController extends AbstractController {


    @Autowired
    private RobotLogService robotLogService;


    @PostMapping("/zeroRobot")
    public R zeroRobotSubmit( @RequestBody RobotRequestDto robotRequestDto) {
        SysUserEntity user = getUser();
        robotRequestDto.setCreateUserId(user.getUserId());
        robotRequestDto.setCreateUserName(user.getUsername());
        return robotLogService.zeroRobotSubmit(robotRequestDto);
    }
    @PostMapping("/successZeroRobot")
    public R successZeroRobot( @RequestBody RobotRequestDto robotRequestDto) {
        robotRequestDto.setUpdateTime(new Date());
        robotRequestDto.setStatus(YesOrNoEnum.ZERO.getType());
        return robotLogService.successZeroRobot(robotRequestDto);
    }




    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("robot:robotlog:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = robotLogService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("robot:robotlog:info")
    public R info(@PathVariable("id") Long id){
		RobotLogEntity robotLog = robotLogService.getById(id);

        return R.ok().put("robotLog", robotLog);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("robot:robotlog:save")
    public R save(@RequestBody RobotLogEntity robotLog){
		robotLogService.save(robotLog);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("robot:robotlog:update")
    public R update(@RequestBody RobotLogEntity robotLog){
		robotLogService.updateById(robotLog);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("robot:robotlog:delete")
    public R delete(@RequestBody Long[] ids){
		robotLogService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
